package com.newretail.springboot.controller;

import com.newretail.springboot.constant.CityErrorInfoEnum;
import com.newretail.springboot.entity.City;
import com.newretail.springboot.result.GlobalErrorInfoException;
import com.newretail.springboot.result.ResultBody;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:gaoxu;
 * @Email:gaoxu@benlai.com
 * @DATE:2018-01-05
 * @version:ver1.0.0
 * @Description: 错误码案例
 */

@RestController
public class ErrorJsonController {

    @RequestMapping(value = "/api/city",method = RequestMethod.GET)
    public ResultBody findOneCity(@RequestParam("cityName") String cityName) throws GlobalErrorInfoException{
        // 入参为空
        if(StringUtils.isEmpty(cityName)){
            throw new GlobalErrorInfoException(CityErrorInfoEnum.PARAMS_NO_COMPLETE);
        }
        City city = new City(1L, 2L, "江苏宿迁市", "是我的故乡!");
        return new ResultBody(city);
    }
}
